﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using Kooboo.CMS.Common.Runtime.Dependency;
using Kooboo.CMS.Sites.Extension.UI;
using Kooboo.CMS.Sites.Extension.UI.TopToolbar;
using Kooboo.Globalization;
using Kooboo.Web.Mvc;

namespace DemoModule.UI
{
    [Dependency(typeof(IToolbarProvider), Key = "DemoModule.UI.ReportButtonToolbar")]
    public class ReportButtonToolbar : IToolbarProvider
    {
        public IEnumerable<ToolbarGroup> GetGroups(RequestContext requestContext)
        {
            return new[]
            {
                new ToolbarGroup
                {
                    DisplayText = "Report",
                    GroupName = "report",
                    IconClass = "preview",
                    Order = 100
                }
            };
        }

        public IEnumerable<ToolbarButton> GetButtons(RequestContext requestContext)
        {
            const string skipRoutes = "Area,Controller,Action";
            var routeValues = requestContext.AllRouteValues();
            foreach (string key in skipRoutes.Split(','))
            {
                routeValues.Remove(key);
            }

            return new List<ToolbarButton>
            {
                new ToolbarButton
                {
                    CommandTarget = new MvcRoute //按钮点击后连接到哪里
                    {
                        Action = "Preview",
                        Controller = "Report",
                        Area = "DemoModule", //我们需要把这个拓展module注册为mvc的area
                        RouteValues = routeValues
                    },
                    CommandText = "Selected items", //按钮显示文本
                    GroupName = "report",
                    HtmlAttributes = new Dictionary<string, object>()
                    {
                        {"data-show-on-check", "Any"},
                        {"data-command-type", "Post"}
                    }
                },
                new ToolbarButton
                {
                    CommandTarget = new MvcRoute //按钮点击后连接到哪里
                    {
                        Action = "Preview",
                        Controller = "Report",
                        Area = "DemoModule", //我们需要把这个拓展module注册为mvc的area
                        RouteValues = routeValues
                    },
                    CommandText = "All items", //按钮显示文本
                    GroupName = "report"
                },
                new ToolbarButton
                {
                    CommandTarget = new MvcRoute //按钮点击后连接到哪里
                    {
                        Action = "PublishDate",
                        Controller = "Report",
                        Area = "DemoModule", //我们需要把这个拓展module注册为mvc的area
                        RouteValues = routeValues
                    },
                    CommandText = "by Date", //按钮显示文本
                    GroupName = "report"
                }
            };
        }

        public MvcRoute[] ApplyTo
        {
            get
            {
                return new[]
                {
                    new MvcRoute
                    {
                        Action = "Index",
                        Controller = "TextContent",
                        Area = "Contents",
                        RouteValues = new Dictionary<string, object>
                        {
                            {"FolderName", "Article"}//这里我们可以加条件，比如我想让他在Article显示，Category中不显示
                        }
                    }
                };
            }
        }
    }
}
